Genotype is a finite sequence of genes.
It can be described by words built of capital letters A–Z of the English alphabet.
Different letters denote different kinds of genes.
A gene can bud and in effect transform into a pair of new genes.
Such transformations are controlled by a finite set of rules.
Every rule of budding can be described by three capital letters
.
Such a description means that gene
can transform into the pair of genes
.
We are using
to denote the special kind of genes called supergenes.
The breeding of a genotype begins from a sequence of supergenes and it consists in controlled budding of chosen genes according to the given rules.
Write a program that:
In the first line of the standard output there is one integer
,
.
In each of the following n lines there is one budding rule.
Such a rule is described by a word consisting of three capital letters A–Z.
We allow budding rules in which the second or the third character denotes a supergene.
In the next line there is written one integer
,
.
In each of the following
lines there is one genotype.
Such a genotype is described by a non-empty word consisting of at most
letters A–Z.
In the
-th of
lines of the standard output there should be written:
-th of the given genotypes, or
For the input data:
6 SAB SBC SAA ACA BCC CBC 3 ABBCAAABCA CCC BA
the correct result is:
3 1 NIE
Task author: Przemyslawa Kanarek.
W razie problemów technicznych ze Szkopułem, prosimy o kontakt mailowy pod adresem szkopul@fri.edu.pl.
Jeśli chciałbyś porozmawiać o zadaniach, rozwiązaniach lub problemach technicznych, odwiedź nasze serwery na Discordzie. Są one moderowane przez społeczność, ale członkowie zespołu wsparcia również aktywnie się tam udzielają.